<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<%
	String path = request.getContextPath();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>query</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css"/>
<link rel="stylesheet" type="text/css" href="<%=path %>/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="<%=path %>/themes/icon.css"/>
<script type="text/javascript" src="<%=path %>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path%>/js/common.js"></script>
<style scoped="scoped">
.textbox{
    height:20px;
    margin:0;
    padding:0 2px;
    box-sizing:content-box;
}
</style>
<script type="text/javascript">
function add(){
	var form = document.forms[1];
	form.action = "<%=path%>/user/addUser.do";
	form.submit();
	waiting();
}

function update(){
	var flag = 0;
	var ids = document.getElementsByName("cb");
	for(var i = 0; i < ids.length; i++){
		if(ids[i].checked){
			document.getElementById("userId").value = ids[i].value;
			flag++;
		}
	}
	if(flag != 1){
		$.messager.alert("操作提示", "请选择一条记录！", "info");
		return false;
	}
	var form = document.forms[1];
	form.action = "<%=path%>/user/editUser.do";
	form.submit();
	waiting();
}

function del(){
	var userId = "";
	var ids = document.getElementsByName("cb");
	for(var i = 0; i < ids.length; i++){
		if(ids[i].checked){
			userId = userId + "," + ids[i].value;
		}
	}
	if(userId == ""){
		$.messager.alert("操作提示", "请选择记录！", "info");
		return false;
	}
	document.getElementById("userId").value = userId;
	$.messager.confirm('Confirm','是否删除所选记录？',function(y){
		if(y){
			var form = document.forms[1];
			form.action = "<%=path%>/user/deleteUser.do";
			form.submit();
			waiting();
		}else {
			return false;
		}
	}); 
}

function allotMenu(){
	var flag = 0;
	var ids = document.getElementsByName("cb");
	for(var i = 0; i < ids.length; i++){
		if(ids[i].checked){
			document.getElementById("userId").value = ids[i].value;
			flag++;
		}
	}
	if(flag != 1){
		$.messager.alert("操作提示", "请选择一条记录！", "info");
		return false;
	}
	var form = document.forms[1];
	form.action = "<%=path%>/usermenu/allotMenu.do";
	form.submit();
	waiting();
}

function selectAll() {
	var cbFlag = document.getElementsByName("cbFlag");
	var ids = document.getElementsByName("cb");
	for ( var i = 0; i < ids.length; i++) {
		if (cbFlag[0].checked) {
			ids[i].checked = true;
		} else {
			ids[i].checked = false;
		}
	}
}

function queryData(){
	document.forms[0].submit();
	waiting();
}

function returnQuery(){
	var form = document.forms[3];
	form.action = "<%=path%>/user/queryUser.do";
	form.submit();
	waiting();
}
</script>
</head>
<body style="background: #FFFFFF">
	<form method="post" action="<%=path%>/user/queryUser.do">
	<fieldset class="fieldset-self">
	<legend>查询用户信息</legend>
	<table width="100%" align="center">
		<tr>
			<td>用户名：</td>
			<td><form:input path="user.userName" id="userName" cssClass="easyui-validatebox"/></td>
			<td>电子邮件：</td>
			<td><form:input path="user.mail" id="mail" cssClass="easyui-validatebox"/></td>
			<td>电话号码：</td>
			<td><form:input path="user.phone" id="phone" cssClass="easyui-validatebox"/></td>
			<td>用户级别：</td>
			<td>
				<!-- 
				<form:select path="user.userLevel" items="${map }" id="userLevel"
					name="userLevel">
				</form:select>
				--> 
				<form:select path="user.userLevel" id="userLevel" 
					cssClass="easyui-combobox" cssStyle="width:150px;">
					<form:option value="" label="" />
					<form:options items="${userLevelMap }" />
				</form:select>
			</td>
		</tr>
		<tr>
			<td colspan="8" align="right">
				<a href="#" class="easyui-linkbutton" icon="icon-search" onclick="queryData();">查询</a>&nbsp;
				<a href="#" class="easyui-linkbutton" icon="icon-reload" onclick="returnQuery();">重置</a>&nbsp;
			</td>
		</tr>
	</table>
	</fieldset>
	</form>
	<form action="#" method="post">
		<input type="hidden" id="userId" name="userId" value="">
	</form>
	<table>
		<tr><td>
	    	<a href="#" class="easyui-linkbutton" icon="icon-add" onclick="add();">添加</a>&nbsp;
			<a href="#" class="easyui-linkbutton" icon="icon-edit" onclick="update();">修改</a>&nbsp;
			<a href="#" class="easyui-linkbutton" icon="icon-remove" onclick="del();">删除</a>&nbsp;
			<c:if test="${userInfo.userLevel == '0'}">
				<a href="#" class="easyui-linkbutton" icon="icon-man" onclick="allotMenu();">分配菜单</a>&nbsp;
			</c:if>
		</td></tr>
	</table>
	<table class="table" width="100%" align="center">
	  <thead>
	  	<tr>
	      <th><input type="checkbox" id="cbFlag" name="cbFlag" onclick="selectAll();"></th>
	      <th>用户名</th>
	      <th>真实姓名</th>
	      <th>电子邮件</th>
	      <th>电话</th>
	      <th>创建时间</th>
	      <th>修改时间</th>
	      <th>级别</th>
	    </tr>
	  </thead>
	  <tbody>
	  	<c:forEach items="${list }" var="user">
			<tr onmouseover="this.bgColor='#EAF2FF'" onmouseout="this.bgColor='#FFFFFF'" align="center">
				<td><input type="checkbox" id="cb" name="cb" value="${user.userId }"></td>
				<td>${user.userName }</td>
				<td>${user.trueName }</td>
				<td>${user.mail }</td>
				<td>${user.phone }</td>
				<td><fmt:formatDate value="${user.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td><fmt:formatDate value="${user.updateTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
				<td>${user.userLevel }</td>
			</tr>
		</c:forEach>
	  </tbody>
	  <tfoot>
	      <td colspan="8">
	      	<form id="page" action="<%=path%>/user/queryUser.do" method="post">
		        <div class="easyui-pagination"
			        data-options="
			        	total : ${pageInfo.totalRecords },
			        	pageSize: ${pageInfo.pageSize},
			        	pageNumber: ${pageInfo.currentPage},
			        	layout:['list','sep','first','prev','links','next','last','sep','refresh'],
			        	onSelectPage: function(pageNumber, pageSize){   
			                easyPage(pageNumber, pageSize);
			            },
			            buttons: [{
				            iconCls:'icon-add',
				            handler:function(){
				                add();
				            }
				        },{
				            iconCls:'icon-edit',
				            handler:function(){
				               update();
				            }
				        },{
				            iconCls:'icon-remove',
				            handler:function(){
				               del();
				            }
				        }]
			        ">
			    </div>
				<form:hidden path="pageInfo.currentPage" id="currentPage"/>
				<form:hidden path="pageInfo.pageSize" id="pageSize"/>
				<form:hidden path="user.userName"/>
				<form:hidden path="user.mail"/>
				<form:hidden path="user.phone"/>
				<form:hidden path="user.userLevel"/>
			</form>
	      </td>
	  </tfoot>
	</table>
	<form></form>
	</body>
</html>
